package br.com.ews.agenda.model.helpers;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import br.com.ews.agenda.model.Agenda;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

public class DataBaseHelper<E> extends OrmLiteSqliteOpenHelper {

    private static final String NOME_BANCO = "sistema.db";
    private static final int VERSAO = 15;

    public DataBaseHelper(Context context) {
        super(context, NOME_BANCO, null, VERSAO);
    }

    @Override
    public void onCreate(SQLiteDatabase db, ConnectionSource src) {
        try {
            // List<String> creates = TableUtils.getCreateTableStatements(src,
            // Agenda.class);
            TableUtils.createTable(src, Agenda.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, ConnectionSource src, int oldVersion, int newVersion) {
        try {
            // List<String> creates = TableUtils.getCreateTableStatements(src,
            // Agenda.class);
            TableUtils.dropTable(src, Agenda.class, true);
            onCreate(db, src);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void close() {
        super.close();
    }

}